package io.renren.modules.sys.service.impl;

import io.renren.common.utils.PageUtils;
import io.renren.modules.sys.service.SysUserService;
import io.renren.modules.sys.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.TiananFuyiDao;
import io.renren.modules.sys.entity.TiananFuyiEntity;
import io.renren.modules.sys.service.TiananFuyiService;


@Service("tiananFuyiService")
public class TiananFuyiServiceImpl extends ServiceImpl<TiananFuyiDao, TiananFuyiEntity> implements TiananFuyiService {

    @Autowired
    TiananFuyiDao tiananFuyiDao;
    @Autowired
    SysUserService sysUserService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        IPage<TiananFuyiEntity> page = this.page(
                new Query<TiananFuyiEntity>().getPage(params),
                new QueryWrapper<TiananFuyiEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<TiananFuyiEntity> list(Map<String, Object> params) {
        String tianid = (String) params.get("tianid");
        List<TiananFuyiEntity> list = tiananFuyiDao.selectList(new QueryWrapper<TiananFuyiEntity>()
                .eq(StringUtil.isNotEmpty(tianid), "tianid", tianid));

        list.forEach(e -> {
            e.setUsername(sysUserService.getById(e.getUserid()).getRealname());
        });


        return list;
    }

    @Override
    public TiananFuyiEntity selectone(Map<String, Object> params) {
        String tianid = (String) params.get("tianid");
        String userid = (String) params.get("userid");
        return tiananFuyiDao.selectOne(new QueryWrapper<TiananFuyiEntity>()
                .eq(StringUtil.isNotEmpty(tianid), "tianid", tianid)
                .eq(StringUtil.isNotEmpty(userid), "userid", userid)
        );
    }

    @Override
    public int updatebyEntity(TiananFuyiEntity tiananFuyiEntity) {


        return 0;
    }

}
